from starlette.endpoints import HTTPEndpoint
from starlette.responses import JSONResponse
from model.ModDepartmentVsBureau import DepartmentVsBureau, depvsbureauSchema
from database import Session, engine
import datetime
from sqlalchemy.sql import text


def update_department_info(session, departmentid: int, bureauid: str):
    # 更新项目部所属县局
    try:
        updateinfo = session.query(DepartmentVsBureau).filter(DepartmentVsBureau.departmentid == departmentid).one_or_none()
        updateinfo.bureauid = bureauid
    except Exception as e:
        raise


def get_department_list(session):
    # 查询项目部信息
    department_list = session.query(DepartmentVsBureau).all()
    return JSONResponse(depvsbureauSchema.dump(department_list, many=True).data)

def get_department_info(session,deparmentid: int):
    #根据部门编号查询部门信息
    department_info = session.query(DepartmentVsBureau).filter(DepartmentVsBureau.departmentid == deparmentid).one_or_none()
    return JSONResponse(depvsbureauSchema.dump(department_info, many=False).data)
